package com.ynet.middleground.user.job;

import com.ifp.framework.ClusterJob;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.user.model.ChannelConfigModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 渠道资源定时任务
 *
 * @author yangbh
 */
@Component
public class ChannelResourceJob extends ClusterJob {

    @Autowired
    private ChannelConfigModel channelConfigModel;

    /**
     * 每日凌晨10分执行job
     * @throws Exception
     */
    // 2020-01-02 不启动定时任务
    //@Scheduled(cron = "0 0 1 */1 * ? ")
    public void test() throws Exception {
        // 是否领导者
        if(!isLeader()){
            IfpLogger.info("job", "程序不执行");
            return;
        }

        // 同步渠道资源
        doSyncChannelResource();
    }

    /**
     * 同步渠道资源
     */
    private void doSyncChannelResource() {

        IfpLogger.info("job", "执行渠道资源配置更新开始");
        channelConfigModel.doSyncChannelResource();
        IfpLogger.info("job", "执行渠道资源配置更新结束");

    }
}
